home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 160 - Disc 1 / MF_UK_160_1.iso / pc / DiscContent / FullSoftware / Amapi61MacEn / Amapi 3D 6.1 Installer / 3SPACE / TSCamera.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  1.5 KB  |  61 lines  |  [AMAS/AMAP]

  1.  
  2. var phiLimit = 0.9 * Math.PI/2;
  3. phiMin = 20
  4. phiMax = 80
  5. //var phi
  6. //var theta
  7.  
  8. function TSCameraMove(cameraId,eventId,dragId)
  9. {
  10.  
  11.     // Get the position of the camera dragger solid
  12.     targetPoint = TSMakePointFromString(TSGetAttribute(cameraId,"targetPoint"));
  13.     // Get the dragger target point
  14.     position    = TSMakePointFromString(TSGetAttribute(dragId,"targetPoint"));
  15.      
  16.     // Create the vector between the camera and the target point ( in spherical coordinates )
  17.     
  18.     var sphericCoords = TSVectorToSphericCoords(TSMakeVector(targetPoint,position))
  19.  
  20.     // Compute the  current rotation angles
  21.  
  22.     switch (eventId)
  23.         {
  24.         case "arrowRight":
  25.         case "padRight":
  26.             sphericCoords.theta += TSDegToRad(10)
  27.             break
  28.             
  29.         case "arrowLeft":
  30.         case "padLeft":
  31.             sphericCoords.theta -= TSDegToRad(10)
  32.             break
  33.             
  34.         case "arrowUp":
  35.         case "padUp":
  36.             newPhi = sphericCoords.phi + TSDegToRad(10)
  37.             if (newPhi < phiLimit && newPhi < TSDegToRad(phiMax)) {
  38.               sphericCoords.phi = newPhi;
  39.             }
  40.             break
  41.             
  42.         case "arrowDown":
  43.         case "padDown":
  44.             newPhi = sphericCoords.phi - TSDegToRad(10)
  45.                 if (newPhi > -phiLimit && newPhi > TSDegToRad(phiMin)) {
  46.               sphericCoords.phi = newPhi;
  47.             }
  48.             break
  49.             
  50.         }
  51.         
  52.     position=TSSphericCoordsToVector(sphericCoords);
  53.     position=TSPointTranslate(position,targetPoint.x,targetPoint.y,targetPoint.z);
  54.     // Move the camera dragger at the new location
  55.     TSUpdateNodeAttribute("dragCamera","targetPoint",TSMakeStringFromPoint(position))
  56.     return sphericCoords;
  57. }    
  58.  
  59.  
  60.  
  61.